package com.zgroup.services

import com.zgroup.domain.InfoRelease
import com.zgroup.domain.Setting

class InfoReleaseService extends DynamicService {

  boolean transactional = true

  def displaylist(params, positionalParams) {
    String query = "from InfoRelease as i where i.publisher = ? and i.keywords like ? "
    //return InfoRelease.findAll(query,positionalParams,[max:params.max, offset:0])
    return paginateList(query, positionalParams, [max: params.max, offset: params.offset, sort: "lastUpdated", order: "desc"], InfoRelease)
  }

  def paginateListByPublisher(pUser, params) {
    String query = "from InfoRelease as i where i.publisher = ? "

    return paginateList(query, [pUser], [max: params.max, offset: params.offset, sort: params.sort, order: params.order], InfoRelease)
    //return paginateList(query,[pUser],[max:params.max, offset:params.offset,sort:"i.i.title",order:params.order],InfoRelease)

  }

  def approve(pInfoReleaseId, pFlag, pApproveUser, approveOption) {

    def info = InfoRelease.get(pInfoReleaseId)
    info.approveFlag = pFlag

    if (pFlag == 1) {
      def setting = Setting.get(1)
      pApproveUser.availableMoney += setting.estateMoneyPresented
      pApproveUser.availablePoint += setting.estatePointPresented
      pApproveUser.availableCoupon += setting.estateCouponPresented
    }
    info.approveUser = pApproveUser
    info.approveOption = approveOption

    info.save()
    return true;

  }
}
